package Array;

public class ChampagneTower {

    /*
        date:2021/5/17
        leetcode：799
        poured:倒入香槟杯数
        query_row:待查询行数
        query_galss:待查寻列数
     */
    public static double Champagne(int poured, int query_row, int query_glass){
        double[][] total = new double[100][100];
        total[0][0] = poured;
        for (int r=0; r<=query_row; r++){
            for (int l=0; l<=r; l++){
                double temp = (total[r][l] - 1) / 2;
                if (temp > 0){
                    total[r+1][l] += temp;
                    total[r+1][l+1] += temp;
                }
            }
        }
        return Math.min(1,total[query_row][query_glass]);
    }

    public static void main(String[] args) {
        System.out.println(Champagne(4,2,1));
    }
}
